package com.twu.user;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created with IntelliJ IDEA.
 * User: root
 * Date: 7/11/13
 * Time: 12:55 AM
 * To change this template use File | Settings | File Templates.
 */
public class UserList {


    private static ArrayList<User> userlist = new ArrayList<User>();

    public UserList() {
    }


    public static void insertUser(User user) {
        //To change body of created methods use File | Settings | File Templates.
        userlist.add(user);
    }


    public static User checkUser(String username, String password) {
        //To change body of created methods use File | Settings | File Templates.

        Iterator<User> user = userlist.iterator();
        while(user.hasNext())
        {
            User it = user.next();
            if( it.getId().equals(username) && it.getPassword().equals(password))
            {
                return it;
            }
        }
        return null;
    }

    public static void showMembershipDetails(PrintStream output)
    {
        output.print("Name\t\tEmail\t\tPhone Number\n");
        Iterator<User> user = userlist.iterator();
        while(user.hasNext())
        {
            User it = user.next();
            output.print(it.getName()+"\t\t"+it.getEmail()+"\t\t"+it.getPhone()+"\n");
        }
    }
}
